﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class userControls_PortfolioFilters : System.Web.UI.UserControl
{

    public delegate void btnFilter_Click(object sender, System.EventArgs e);
    public event btnFilter_Click cClick;

    private void UserControl1_Click(object sender, System.EventArgs e)
    {
        if (cClick != null)
            cClick(sender, e);
    }

    private string _Grouping;
    public string Grouping
    { 
        get { return _Grouping; }
        set { _Grouping = value; }
    }

    private string _PropertiesForName;
    public string PropertiesForName
    {
        get { return _PropertiesForName; }
        set { _PropertiesForName = value; }
    }

public string ErrorMessage
    {
        set { 
            lblErrorMessage.Text= value;
            tdErrorMessage.Style["display"] = "";
        }
    }
    private string lnkbtn = string.Empty;
    protected void Page_Load(object sender, EventArgs e)
    {


        lblFillter.Text = "Filter " + Grouping;
        Panel1.GroupingText = Grouping + " Filter Settings";

        lblList.Enabled = Grouping == "Portfolios" || Session["PropertiesForName"] != null;

        if (!IsPostBack)
        {
            Page.Form.DefaultButton = lblFillter.UniqueID;
                getCookie("Addresses", txtAddresses);
            getCookie("Greens", txtGreens);
            getCookie("Lit", txtLit);
            getCookie("InService", txtInService);
            getCookie("Saturation", txtSaturation);
            getCookie("TotalSubscribers", txtTotalSubscribers);
            getCookie("IPTVSubscribers", txtIPTVSubscribers);
            getCookie("HSIASubscribers", txtHSIASubscribers);
            getCookie("VOIPSubscribers", txtVOIPSubscribers);
            getCookie("TotalRevenues", txtTotalRevenues);
            getCookie("IPTVRevenues", txtIPTVRevenues);
            getCookie("HSIARevenues", txtHSIARevenues);
            getCookie("VOIPRevenues", txtVOIPRevenues);
            getCookie("OtherRevenues", txtOtherRevenues);
            getCookie("IPTVPercentage", txtIPTVPercentage);
            getCookie("HSIAPercentage", txtHSIAPercentage);
            getCookie("VOIPPercentage", txtVOIPPercentage);
            getCookie("OtherPercentage", txtOtherPercentage);
            getCookie("TotalPerSubscriber", txtTotalPerSubscriber);
            getCookie("IPTVPerSubscriber", txtIPTVPerSubscriber);
            getCookie("HSIAPerSubscriber", txtHSIAPerSubscriber);
            getCookie("VOIPPerSubscriber", txtVOIPPerSubscriber);
            getCookie("OtherPerSubscriber", txtOtherPerSubscriber);
            getCookie("ddlColumnName", ddlColumnName);
            ddlColumnName_SelectedIndexChanged(sender, e);
            lblList.ToolTip = "Press Alt-L to List " + Grouping;
            lblFillter.ToolTip = "Press Alt-F to Filter " + Grouping;

        }
    }

    protected void getCookie(string psCookieName, TextBox txt)
    {
        string sCookie = String.Format("{0}_{1}", Grouping, psCookieName);
        txt.Text = Request.Cookies[sCookie] == null ? "" :
        Request.Cookies[sCookie].Value;
    }

    protected void getCookie(string psCookieName, DropDownList ddl)
    {
        string sCookie = String.Format("{0}_{1}", Grouping, psCookieName);
        ddl.SelectedIndex = Request.Cookies[sCookie] == null ? 0 :
       Convert.ToInt16(Request.Cookies[sCookie].Value);
    }

    protected void Page_PreRender(object sender, EventArgs e)
    {
        //
        lblHasValues.Visible =
           txtTotalSubscribers.Text.Length > 0 ||
       txtIPTVSubscribers.Text.Length > 0 ||
       txtHSIASubscribers.Text.Length > 0 ||
       txtVOIPSubscribers.Text.Length > 0 ||
       txtTotalRevenues.Text.Length > 0 ||
       txtIPTVRevenues.Text.Length > 0 ||
       txtHSIARevenues.Text.Length > 0 ||
       txtVOIPRevenues.Text.Length > 0 ||
       txtOtherRevenues.Text.Length > 0 ||
       txtIPTVPercentage.Text.Length > 0 ||
       txtHSIAPercentage.Text.Length > 0 ||
       txtVOIPPercentage.Text.Length > 0 ||
       txtOtherPercentage.Text.Length > 0 ||
       txtTotalPerSubscriber.Text.Length > 0 ||
       txtIPTVPerSubscriber.Text.Length > 0 ||
       txtHSIAPerSubscriber.Text.Length > 0 ||
       txtVOIPPerSubscriber.Text.Length > 0 ||
       txtOtherPerSubscriber.Text.Length > 0;

    }


    public void RefreshMetadata(object sender, EventArgs e)
    {
    }

    protected void chkAllDimensions_CheckedChanged(object sender, EventArgs e)
    {
        txtAddresses.Text = "";
        txtGreens.Text = "";
        txtInService.Text = "";
        txtLit.Text = "";
        txtSaturation.Text = "";
        txtTotalSubscribers.Text = "";
        txtIPTVSubscribers.Text = "";
        txtHSIASubscribers.Text = "";
        txtVOIPSubscribers.Text = "";
        txtTotalRevenues.Text = "";
        txtIPTVRevenues.Text = "";
        txtHSIARevenues.Text = "";
        txtVOIPRevenues.Text = "";
        txtOtherRevenues.Text = "";
        txtTotalPercentage.Text = "";
        txtIPTVPercentage.Text = "";
        txtHSIAPercentage.Text = "";
        txtVOIPPercentage.Text = "";
        txtOtherPercentage.Text = "";
        txtTotalPerSubscriber.Text = "";
        txtIPTVPerSubscriber.Text = "";
        txtHSIAPerSubscriber.Text = "";
        txtVOIPPerSubscriber.Text = "";
        txtOtherPerSubscriber.Text = "";

        chkAllDimensions.Checked = false;
        lblFillter_Click(sender, e);
    }

    protected void ddlColumnName_SelectedIndexChanged(object sender, EventArgs e)
    {
        tblSubscribers.Visible = false; ;
        tblRevenues.Visible = false; ;
        tblPercentage.Visible = false; ;
        tblPerSubscriber.Visible = false;
        switch (ddlColumnName.SelectedValue)
        {
            case "Subscribers":
                tblSubscribers.Visible = true;
                break;
            case "Revenues":
                tblRevenues.Visible = true;
                break;
            case "Percentage":
                tblPercentage.Visible = true;
                break;
            case "PerSubscriber":
                tblPerSubscriber.Visible = true;
                break;
            default:
                break;
        }

    }

    protected void imgbtnRunFilter_Click(object sender, ImageClickEventArgs e)
    {

    }


    protected void setCookie(string psCookie, string psValue, DateTime pdtExp)
    {
        if (Request.Cookies[psCookie] == null)
            Response.Cookies.Add(new HttpCookie(psCookie, psValue));
        else
            Response.Cookies[psCookie].Value = psValue;
        Request.Cookies[psCookie].Value = psValue;
        Response.Cookies[psCookie].Expires = pdtExp;
    }

    protected void lblFillter_Click(object sender, EventArgs e)
    {
        string sCookie = String.Empty; DateTime dtExp = DateTime.Now.AddDays(30);
        sCookie = String.Format("{0}_{1}", Grouping, "Addresses"); setCookie(sCookie, txtAddresses.Text, dtExp);
        sCookie = String.Format("{0}_{1}", Grouping, "Greens"); setCookie(sCookie, txtGreens.Text, dtExp);
        sCookie = String.Format("{0}_{1}", Grouping, "InService"); setCookie(sCookie, txtInService.Text, dtExp);
        sCookie = String.Format("{0}_{1}", Grouping, "Lit"); setCookie(sCookie, txtLit.Text, dtExp);
        sCookie = String.Format("{0}_{1}", Grouping, "Saturation"); setCookie(sCookie, txtSaturation.Text, dtExp);
        sCookie = String.Format("{0}_{1}", Grouping, "TotalSubscribers"); setCookie(sCookie, txtTotalSubscribers.Text, dtExp);
        sCookie = String.Format("{0}_{1}", Grouping, "IPTVSubscribers"); setCookie(sCookie, txtIPTVSubscribers.Text, dtExp);
        sCookie = String.Format("{0}_{1}", Grouping, "HSIASubscribers"); setCookie(sCookie, txtHSIASubscribers.Text, dtExp);
        sCookie = String.Format("{0}_{1}", Grouping, "VOIPSubscribers"); setCookie(sCookie, txtVOIPSubscribers.Text, dtExp);
        sCookie = String.Format("{0}_{1}", Grouping, "TotalRevenues"); setCookie(sCookie, txtTotalRevenues.Text, dtExp);
        sCookie = String.Format("{0}_{1}", Grouping, "IPTVRevenues"); setCookie(sCookie, txtIPTVRevenues.Text, dtExp);
        sCookie = String.Format("{0}_{1}", Grouping, "HSIARevenues"); setCookie(sCookie, txtHSIARevenues.Text, dtExp);
        sCookie = String.Format("{0}_{1}", Grouping, "VOIPRevenues"); setCookie(sCookie, txtVOIPRevenues.Text, dtExp);
        sCookie = String.Format("{0}_{1}", Grouping, "OtherRevenues"); setCookie(sCookie, txtOtherRevenues.Text, dtExp);
        sCookie = String.Format("{0}_{1}", Grouping, "TotalPercentage"); setCookie(sCookie, txtTotalPercentage.Text, dtExp);
        sCookie = String.Format("{0}_{1}", Grouping, "IPTVPercentage"); setCookie(sCookie, txtIPTVPercentage.Text, dtExp);
        sCookie = String.Format("{0}_{1}", Grouping, "HSIAPercentage"); setCookie(sCookie, txtHSIAPercentage.Text, dtExp);
        sCookie = String.Format("{0}_{1}", Grouping, "VOIPPercentage"); setCookie(sCookie, txtVOIPPercentage.Text, dtExp);
        sCookie = String.Format("{0}_{1}", Grouping, "OtherPercentage"); setCookie(sCookie, txtOtherPercentage.Text, dtExp);
        sCookie = String.Format("{0}_{1}", Grouping, "TotalPerSubscriber"); setCookie(sCookie, txtTotalPerSubscriber.Text, dtExp);
        sCookie = String.Format("{0}_{1}", Grouping, "IPTVPerSubscriber"); setCookie(sCookie, txtIPTVPerSubscriber.Text, dtExp);
        sCookie = String.Format("{0}_{1}", Grouping, "HSIAPerSubscriber"); setCookie(sCookie, txtHSIAPerSubscriber.Text, dtExp);
        sCookie = String.Format("{0}_{1}", Grouping, "VOIPPerSubscriber"); setCookie(sCookie, txtVOIPPerSubscriber.Text, dtExp);
        sCookie = String.Format("{0}_{1}", Grouping, "OtherPerSubscriber"); setCookie(sCookie, txtOtherPerSubscriber.Text, dtExp);
        sCookie = String.Format("{0}_{1}", Grouping, "ddlColumnName"); setCookie(sCookie, ddlColumnName.SelectedIndex.ToString(), dtExp);

        UserControl1_Click(sender, e);
    }
    protected void lblList_Click(object sender, EventArgs e)
    {

    }
}